04. Experimenting with FOV

Experimenting with FOV

Now it is one thing for us to talk about these AR headsets having a limited field of view, but it is another thing for you to experience it. So let’s build a prototype in Unity starting with a brand new Unity project.

For this we will be using a Post-Processing Effect called a Vignette to manipulate the field of view, which is provided by Unity. You can get the package from the Unity Asset Store.

Once you import that and Google VR SDK, we need to setup GVR. Add the GVREditorEmulator prefab to your scene and assign the Main Camera to the camera property of the script. Also, make sure to enable Virtual Reality support in your player settings.

To use the post processing stack, we need to create a Post Processing Profile file in our project window. This file offers us a bunch of post processing effects that we can use to enhance how our VR world looks. But in this case, we want to focus on the Vignette property and turn it on.

Next let’s assign it to our camera by creating a Post-Processing Behavior component on our camera. Then drag, the profile onto the Profile property.

With that setup, feel free to experiment with some of the properties on vignette. You can also add some geometry to your scene to really see the effect.

After playing around with this a bit, you will notice the sliders don’t give us a sense of what the exact field of view we are using is. For that, we will need to write a basic script to convert field of view angles into a value between 0 and 1.

To do this, let’s create a C# script called FOVShrink.cs. Here is the completed script for your reference.

using UnityEngine;
using UnityEngine.PostProcessing;

public class FOVShrink : MonoBehaviour {

    public float simulatedFOV;

    public float IPD;
    public float SCREEN_DISTANCE;

    public PostProcessingBehaviour postProcess;

    private VignetteModel vModel;
    private float maxFOV;

    // Use this for initialization
    void Start () {
        vModel = postProcess.profile.vignette;
        maxFOV = Mathf.Rad2Deg * Mathf.Atan2(IPD / 2f, SCREEN_DISTANCE);
    }

    // Update is called once per frame
    void Update () {
        VignetteModel.Settings settings = vModel.settings;
        settings.intensity = 1f - Mathf.Clamp01(simulatedFOV / maxFOV);
        vModel.settings = settings;
    }
}

We start with a few public variables to create a simulated field of view and to calculate the field of view of your device. In the inspector you will want to assign values like so:

The best way to calculate the max field of view and use that to get a percentage of the field of view we want to simulate. To approximate this, we can measure the IPD or Inter-pupillary distance and distance between our lenses and phone screen.

Using a little Trigonometry, we can calculate that the angle is the tangent inverse of the IPD divided by the distance to the screen.

With that information, we can calculate the max field of view in degrees is

Mathf.Rad2Deg * (Mathf.Atan2(IPD / 2f, SCREEN_DISTANCE) ) ;

Then we can change the vignette intensity, by getting the percentage of the maxFOV for our intensity.

fovControl.intensity = 1f - Mathf.Clamp01(simulatedFOV / maxFOV);

Make sure to test this out in your Cardboard as well, but as you can see here, we are able to simulate a wide range of Fields of view.

Great work!